package com.ruoyi.web.controller.user;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.domain.UserEduAdmin;
import com.ruoyi.service.IUserEduAdminService;
import com.ruoyi.vo.UserEduAdminPageVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教育局管理员用户Controller
 * 
 * @author longxianghang
 * @date 2024-05-31
 */
@Controller
@RequestMapping("biz/user")
public class UserEduAdminController extends BaseController
{

    @Autowired
    private IUserEduAdminService userEduAdminService;

    /**
     * 查询用户列表
     */
    @RequiresPermissions("user:test:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserEduAdminPageVo userEduAdminPageVo)
    {
        startPage();
        List<UserEduAdminPageVo> list = userEduAdminService.selectUserEduAdminList(userEduAdminPageVo);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @RequiresPermissions("user:test:export")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserEduAdminPageVo userEduAdminPageVo)
    {
        List<UserEduAdminPageVo> list = userEduAdminService.selectUserEduAdminList(userEduAdminPageVo);
        ExcelUtil<UserEduAdminPageVo> util = new ExcelUtil<UserEduAdminPageVo>(UserEduAdminPageVo.class);
        return util.exportExcel(list, "用户数据");
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("user:test:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody UserEduAdmin userEduAdmin)
    {
        userEduAdmin.setCreateBy(getLoginName());
        userEduAdmin.setCreateTime(DateUtils.getNowDate());
        return toAjax(userEduAdminService.insertUserEduAdmin(userEduAdmin));
    }

    /**
     * 根据userId查询用户信息
     */
    @RequiresPermissions("user:test:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @GetMapping("/getDsUserById/{userId}")
    @ResponseBody
    public AjaxResult getDsUserById(@PathVariable("userId") Long userId)
    {
        UserEduAdmin userEduAdmin = userEduAdminService.selectUserEduAdminByUserId(userId);
        return AjaxResult.success(userEduAdmin);
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("user:test:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestBody UserEduAdmin userEduAdmin)
    {
        userEduAdmin.setUpdateBy(getLoginName());
        userEduAdmin.setUpdateTime(DateUtils.getNowDate());
        return toAjax(userEduAdminService.updateUserEduAdmin(userEduAdmin));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("user:test:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @DeleteMapping( "/remove/{userId}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long userId)
    {
        return toAjax(userEduAdminService.deleteUserEduAdminByUserId(userId));
    }
}
